-
Notifications
You must be signed in to change notification settings - Fork 189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Drop-in LuaJIT replacement in place of Lua 5.4 #673
base: main
Are you sure you want to change the base?
Conversation
I'm a bit confused by this. What caused the difference? Do we want more detailed type info when printing to string? Don't we just want the string so we can operate on it as an exact string? |
Lua 5.4 introduced the Of course, LuaJIT being based on 5.2, does not have that; instead, the
It's optional, but as I'm already composing the string anyway to bring back the functionality, putting in more info doesn't sound bad - it's mostly used for debugging after all (i.e., local ksl = StaticFindObject("/Script/Engine.Default__KismetSystemLibrary")
print(tostring(ksl))
print(("%016X"):format(ksl:GetAddress())) will print different addresses for vanilla UE4SS.) (P.S. I forgot to mention that this
I'm not sure what you're referring to here, but if you're talking about UObject |
Can you please pull latest main into your branch and resolve conflicts, I would like to test it. |
* Replace Lua 5.4 with LuaJIT, with compat layer for used functions that don't exist, as a drop-in replacement. * Third-party package 'luajit2' was modified from 'openresty-luajit' xrepo package, to support recent versions. * ConsoleCommandsMod modified to use bitlib instead of Lua 5.3+ bitops
Rebased. |
In case you're still working on it. Want to report my initial feedback. EDIT: It looks like the problem might be indeed json.lua related or duo to the overall complexity of the mod. None of my other mods seems to cause any issues and one of them uses an infinite loop as well. EDIT2: LoopAsync(250, function()
ExecuteInGameThread(function()
local myPlayer = AFUtils.GetMyPlayer()
if myPlayer then
end
end)
return false
end) After a while I got error:
The JIT version will need a LOT of testing to make sure that nothing breaks on the lua stack. |
Description
This PR replaces vanilla Lua 5.4 (from LuaRaw dep) with LuaJIT, hoping to provide large performance improvements, and advanced functionality with FFI to, e.g., access raw game/process memory, interact with C datatypes, and load and use external C libraries (that does not need to be (re-)built for Lua).
A compatibility layer is also made to emplace Lua 5.4 functions that are not present in Lua 5.2/LuaJIT, some implementing similar functionality, some as workarounds, some as no-ops. So being a drop-in replacement, it probably can't ensure 100% compatibility with the Lua 5.4 API, which may cause issues with UE4SS - but so far I have not seen any (yet).
OpenResty's LuaJIT branch is used instead of upstream to make use of tagged releases (upstream rolling release tag does not refer to a single commit throughout time), and this also probably ensures a bit of stability. Xrepo packages for upstream/openresty LuaJIT exist but they seem to be meant for old versions of LuaJIT 2.1.0b3, so I ported over the scripts and modified it to work with current versions.
Also added __tostring metamethods to UE4SS objects, since printing them with the current LuaJIT replacement does not print as it used to anymore (they only appear like
userdata: 0x07ffd3adb33f09a0
). Now they should print with more detailed type info (subtype, etc. along with address), see screenshots.Obviously, Lua 5.3+ syntax won't work anymore, like bitwise operators, and 5.4's
<const>
markers. (Changed ConsoleCommandsMod to use thebit
library from LuaJIT instead). Other than that, existing Lua scripts should work fine.As mentioned, JIT should help with performance, and FFI would allow for easily loading C libraries without the need to do it through the Lua C API, among other things. An example usage is shown under screenshots, where a UE4SS Lua script creates a local web server using libmicrohttpd via FFI.
So far seems to work with two games I tested this on. UE4SS functions work, script reloading works, callbacks seem to be fine too. But I have done extensive testing for everything Lua, hence:
Important
This PR is a DRAFT as it has not seen extensive testing yet and is likely to break obvious and non-obvious things. Testing would be much appreciated.
Type of change
How Has This Been Tested?
Haven't done detailed testing for compat aside from using the same Lua mods (base and custom) on the JIT build. UE4SS functions seem to work fine. Tested FFI functionality, and the __tostring metamethods for some UE4SS objects.
Checklist
Screenshots
Screenshots
__tostring metamethods addition - Source
webserver FFI usage demo - Source - (video may be flashing a bit)
lyrth_280924_mkEgdWUvGx.mov